const Service = require("egg").Service;

class ForwardService extends Service {
    async searchForward(mywxid, wxid) {
        const { ctx } = this;
        try {
            const forward = await ctx.model.Forward.findOne({
                wxid: wxid,
                ownerWxid: mywxid,
                status: true,
            });
            return forward;
        } catch (error) {
            ctx.logger.error("查询转发配置失败:", error);
            return null;
        }
    }

    async createForwardTask(ownerWxid, wxid, msgtype, message) {
        const { ctx } = this;
        try {
            const forward = await ctx.model.Forwardtask.create({
                wxid,
                ownerWxid,
                msgtype,
                message,
                status: 0,
            });
            ctx.logger.info("消息已保存到转发队列中");
            return forward;
        } catch (error) {
            ctx.logger.error("保存失败:", error);
            return null;
        }
    }


    
}

module.exports = ForwardService;
